Skip to content

Restore and fix SpillPointers pass #4570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 6, 2022
Merged

Restore and fix SpillPointers pass #4570

merged 11 commits into from
Jun 6, 2022

Conversation

kripken
Copy link
Member

@kripken kripken commented Apr 1, 2022

Reverts the removal in #3261, fixes compile errors in internal API
changes since then, and flips the direction of the stack for the
wasm backend.

(Can see individual commits for each part of that.)

We should figure out a way to actually test this, though, if we want
to restore it.

@ChrisJefferson
Copy link

I tried making an example test (this code is far too big of course!)

https://gist.github.com/ChrisJefferson/3d0813c40b130d1da5e04dc92cc5b36c -- also a second file containing a function id which just returns it's argument, just to stop the compiler optimising away the local variable.

With emcc -O1 this code fails, then passes with the "Spill Pointers" pass. With -O2 however it fails with "spill pointers", and more worryingly it output looks corrupted (the global pointer which should be constant changes value at some point while printing).

@kripken
Copy link
Member Author

kripken commented Apr 12, 2022

@ChrisJefferson Thanks!

The challenge will be testing it here in binaryen though. I'm not sure atm how to do that. I also probably won't have time to look into it soon, sorry, but perhaps someone else can take this PR as a starting point.

@ChrisJefferson
Copy link

Thanks. Is there any place where a test might live? (I could take a look at existing tests), or is there not really a test framework to run an optimiser on some code, and check the result?

@kripken
Copy link
Member Author

kripken commented Jun 3, 2022

@ChrisJefferson Sorry for the late response. We do have tests to run the optimizer and see the code that results (tests/lit/, tests/passes/ - and this PR has a test there) but only running the code would have noticed the wrong stack direction... and that requires a full program that doesn't really fit in the test suite here. So this is an awkward situation, and I don't have a good idea.

However, this has come up again in emscripten-core/emscripten#17131 (comment) and so I think we should just land this, and figure out more detailed testing later (perhaps on the emscripten side?)

@kripken kripken marked this pull request as ready for review June 3, 2022 16:55
@kripken kripken requested review from aheejin and tlively June 3, 2022 16:55
src/abi/stack.h Outdated
// used by Emscripten. First, look for a global initialized to an
// imported variable named "STACKTOP" in environment "env".
auto* stackPointer =
GlobalUtils::getGlobalInitializedToImport(wasm, ENV, "STACKTOP");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STACKTOP is not a thing in emscripten anymore.

src/abi/stack.h Outdated
if (globalGet) {
stackPointer = wasm.getGlobal(globalGet->name);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have getStackPointerGlobal in src/wasm-emscripten.h today

@sbc100
Copy link
Member

sbc100 commented Jun 3, 2022

Would be nice to had a more readable/smaller test in tests/lit.. but not going to block this change on that.

Shame about re-introducing those two header files just for this one pass :(

@kripken
Copy link
Member Author

kripken commented Jun 3, 2022

Nice, thanks, getStackPointerGlobal makes this a lot cleaner...

I think in this PR it's best to keep the test identical to before, so this is a clean reversion of the removal. We can improve the test later if we want.

Updated after feedback.

@kripken
Copy link
Member Author

kripken commented Jun 3, 2022

Oh, we can at least remove one header here, I did that now: it is easy to get the pointer type since we've added indexType to memories (we added that for wasm64, I believe).

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly rubberstamp LGTM since this is a revert. It would be nice to port the test to lit, though.

@kripken kripken merged commit ec88ea6 into main Jun 6, 2022
@kripken kripken deleted the spill branch June 6, 2022 20:24
Copy link

@UpToDate2010 UpToDate2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants